﻿using Application.MainModule.GroupBranchCurrencyManagement;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Domain.MainModule.GroupBranches;
using Domain.MainModule.Entities;
using System.Collections.Generic;
using Infraestructure.CrossCutting.IoC;

namespace Application.MainModule.Tests
{
    /// <summary>
    ///This is a test class for GroupBranchCurrencyManagementServiceTest and is intended
    ///to contain all GroupBranchCurrencyManagementServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class GroupBranchCurrencyManagementServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for AddGroupBranch
        ///</summary>
        [TestMethod()]
        public void AddGroupBranch_Invoke_Test()
        {
            //Arrange
            IGroupBranchCurrencyManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IGroupBranchCurrencyManagementService>();
            Guid groupBranchId = Guid.NewGuid();
            GroupBranchCurrency groupBranch = new GroupBranchCurrency()
            {
                GroupBranchCurrencyId = groupBranchId,                
            };
            GroupBranchCurrency result;

            //Act
            target.AddGroupBranchCurrency(groupBranch);
            result = target.FindGroupBranchCurrencyById(groupBranchId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(groupBranchId, result.GroupBranchCurrencyId);
            target.RemoveGroupBranchCurrency(result);
        }

        /// <summary>
        ///A test for ChangeGroupBranch
        ///</summary>
        [TestMethod()]
        public void ChangeGroupBranch_Invoke_Test()
        {
            //Arrange
            IGroupBranchCurrencyManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IGroupBranchCurrencyManagementService>();
            Guid groupBranchId = Guid.Parse("ABCDF456-1234-AABB-AAFF-123456BBBBBB");
 
            //Act
            GroupBranchCurrency groupBranch = target.FindGroupBranchCurrencyById(groupBranchId);
            groupBranch.OperationType.Name = "new operation type name";
            target.ChangeGroupBranchCurrency(groupBranch);
            GroupBranchCurrency result = target.FindGroupBranchCurrencyById(groupBranchId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("new operation type name", result.OperationType.Name);
        }

		/// <summary>
        ///A test for FindGroupBranchById
        ///</summary>
        [TestMethod()]
        public void FindGroupBranchById_Invoke_Test()
        {
            //Arrange
            IGroupBranchCurrencyManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IGroupBranchCurrencyManagementService>();
            Guid groupBranchId = Guid.Parse("ABCDF456-1234-AABB-AAFF-123456654321");

            //Act 
            GroupBranchCurrency groupBranch = target.FindGroupBranchCurrencyById(groupBranchId);

            //Assert
            Assert.IsNotNull(groupBranch);
            Assert.AreEqual(groupBranchId, groupBranch.GroupBranchCurrencyId);
        }
		
        /// <summary>
        ///A test for FindGroupBranchByCurrencyId
        ///</summary>
        [TestMethod()]
        public void FindGroupBranchByCurrencyId_Invoke_Test()
        {
            //Arrange
            IGroupBranchCurrencyManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IGroupBranchCurrencyManagementService>();
            Guid currencyId = Guid.Parse("ABCDF456-1234-AABB-AAFF-123456DBBBBB");
            List<GroupBranchCurrency> actual;
            //Act
            actual = target.FindGroupBranchCurrencyByCurrencyId(currencyId);

            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(currencyId, actual[0].CurrencyId);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void RemoveGroupBranch_Invoke_NullItemThrowNewArgumentNullException_Test()
        {
            //Arrange
            IGroupBranchCurrencyManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IGroupBranchCurrencyManagementService>();

            //Act
            target.RemoveGroupBranchCurrency(null);
        }

        /// <summary>
        ///A test for RemoveGroupBranch
        ///</summary>
        [TestMethod()]
        public void RemoveGroupBranch_Invoke_Test()
        {
            //Arrange
            IGroupBranchCurrencyManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IGroupBranchCurrencyManagementService>();
            GroupBranchCurrency groupBranch = null;

            //Act
            groupBranch = target.FindGroupBranchCurrencyById(Guid.Parse("ABCDF456-1234-AABB-AAFF-123456BBBBBB"));
            target.RemoveGroupBranchCurrency(groupBranch);

            //Assert
            GroupBranchCurrency result = target.FindGroupBranchCurrencyById(Guid.Parse("ABCDF456-1234-AABB-AAFF-123456BBBBBB"));
            Assert.IsNull(result);
            groupBranch = new GroupBranchCurrency()
                    {
                        GroupBranchCurrencyId = Guid.Parse("ABCDF456-1234-AABB-AAFF-123456BBBBBB"),
                        OperationType = new OperationType()
                        {
                            Name = "operation 01"
                        },
                        CurrencyId = Guid.Parse("ABCDF456-1234-AABB-AAFF-123456FBBBBB")
                    };
            target.AddGroupBranchCurrency(groupBranch);
        }
    }
}
